package com.ycy.smartcourseselection.config;

import com.ycy.smartcourseselection.common.JwtInterceptor;
import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration  //所有的配置类都要加此注解
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(@NotNull InterceptorRegistry registry) {
        // excludePathPatterns()设置的是排除的地址。排除的"/"为微信给该后端服务发送的请求
        registry.addInterceptor(jwtInterceptor())  //注册写的JwtInterceptor类
                .addPathPatterns("/**")  //拦截所有请求，通过判断token是否合法，决定是否需要登录
                // .excludePathPatterns("/**/login","/getQrCode","/loginByQrCode","/swagger-resources","/v2/api-docs");  //这些路径的请求不验证
                .excludePathPatterns("/","/login","/loginByQrCode","/getQrCode","/file/download","/teacher/getInfo","/student/getInfo","/**/fileExport");  //线上,禁用接口文档
                // .excludePathPatterns("/**/**");  //开发阶段排除全部接口
    }

    @Bean
    //注入到springboot中
    public JwtInterceptor jwtInterceptor() {
        return new JwtInterceptor();
    }
}
